import { tenantItem } from '/@/api/measurement-center/measurement-sdr/model/sdrModel';
import { measurementHttp } from '/@/utils/http/axios';
import {
  ApiDetailItem,
  ApiItem,
  ApiPageParams,
  ApiPageResult,
  ApiSubListItem,
  ApiSubListParams,
  AppItem,
  SubDetailItem,
  SubListParams,
  TenantDetailItem,
  TenantListParams,
  TenantSubListParams,
} from '/@/api/measurement-center/function-statistic/model/statisticModel';

enum Api {
  GET_APP_LIST = '/v1/measurement/function/appList',
  GET_API_LIST = '/v1/measurement/function/apiList',
  GET_TENANT_LIST = '/v1/measurement/function/tenantList',
  GET_API_PAGE = '/v1/measurement/function/apiPage',
  GET_API_SUB_PAGE = '/v1/measurement/function/apiSubList',
  GET_API_DETAIL = '/v1/measurement/function/apiDetail',
  GET_TENANT_SUB_PAGE = '/v1/measurement/function/tenantSubList',
  GET_TENANT_PAGE = '/v1/measurement/function/tenantPage',
  GET_TENANT_DETAIL = '/v1/measurement/function/tenantDetail',
  GET_SUB_DETAIL = '/v1/measurement/function/singleDetail',
}

export const getRecordAppList = () => {
  return measurementHttp.get<AppItem[]>({ url: Api.GET_APP_LIST });
};

export const getRecordApiList = (params: []) => {
  if (params === undefined) {
    return measurementHttp.post<ApiItem[]>({ url: Api.GET_API_LIST });
  } else {
    return measurementHttp.post<ApiItem[]>({ url: Api.GET_API_LIST, params });
  }
};

export const getRecordTenantList = () => {
  return measurementHttp.get<tenantItem[]>({ url: Api.GET_TENANT_LIST });
};
export const getApiList = (params: ApiPageParams) => {
  return measurementHttp.post<ApiPageResult>({ url: Api.GET_API_PAGE, params });
};

export const getApiSubList = (params: ApiSubListParams) => {
  const result = measurementHttp.get<ApiSubListItem>({ url: Api.GET_API_SUB_PAGE, params });
  return result;
};

export const getApiDetail = (params: ApiSubListParams) => {
  return measurementHttp.get<ApiDetailItem[]>({ url: Api.GET_API_DETAIL, params });
};

export const getTenantList = (params: TenantListParams) => {
  return measurementHttp.post<ApiPageResult>({ url: Api.GET_TENANT_PAGE, params });
};

export const getTenantSubList = (params: TenantSubListParams) => {
  return measurementHttp.get<ApiPageResult>({ url: Api.GET_TENANT_SUB_PAGE, params });
};

export const getTenantDetail = (params: TenantSubListParams) => {
  return measurementHttp.get<TenantDetailItem[]>({ url: Api.GET_TENANT_DETAIL, params });
};

export const getSingleDetail = (params: SubListParams) => {
  return measurementHttp.get<SubDetailItem>({ url: Api.GET_SUB_DETAIL, params });
};
